<template>
  <div class="songs-container">
    <div class="tab-bar">
      <span class="item" @click="tag=0" :class="{active:tag==0}">全部</span>
      <span class="item" @click="tag=7" :class="{active:tag==7}">华语</span>
      <span class="item" @click="tag=96" :class="{active:tag==96}">欧美</span>
      <span class="item" @click="tag=8" :class="{active:tag==8}">日本</span>
      <span class="item" @click="tag=16" :class="{active:tag==16}">韩国</span>
    </div>
    <!-- 底部的table -->
    <table class="el-table playlit-table">
      <thead>
        <th></th>
        <th></th>
        <th>音乐标题</th>
        <th>歌手</th>
        <th>专辑</th>
        <th>时长</th>
      </thead>
      <tbody>
        <tr class="el-table__row" v-for="(list, index) in lists" :key="index">
          <td>{{index+1}}</td>
          <td>
            <div class="img-wrap">
              <img v-lazy="list.album.picUrl" alt="" />
              <span @click="play(list.id)" class="iconfont icon-play"></span>
            </div>
          </td>
          <td>
            <div class="song-wrap">
              <div class="name-wrap">
                <span>{{list.name}}</span>
                <span class="iconfont icon-mv"></span>
              </div>
              <span></span>
            </div>
          </td>
          <td>{{list.artists[0].name}}</td>
          <td>{{list.album.name}}</td>
          <td>{{list.duration | date-format}}</td>
        </tr>
      </tbody>
    </table>
  </div>
</template>

<script>
import axios from 'axios'
export default {
  name: 'songs',
  data() {
    return {
      // 歌曲列表
      lists:[],
      // 分类
      tag:'0'
    };
  },
  watch:{
    tag(){
    this.getList()
    }
  },
  created() {
   this.getList()
  },
  methods: {
    // 获取最新音乐数据
    getList(){
    axios({
      url:'https://autumnfish.cn/top/song',
      method:'get',
      params:{
        type:this.tag
      }
    }).then(res=>{
      console.log(res);
      this.lists = res.data.data
    })
    },
    play(id){
    axios({
      url:' https://autumnfish.cn/song/url',
      method:'get',
      params:{
        id
      }
    }).then(res=>{
      console.log(res);
      let url = res.data.data[0].url
      // 直接获取父组件，可以修改任意的值
     this.$parent.musicUrl = url
    })
  }
  },
  
};
</script>

<style >

</style>
